<template>
  <div class="box">
    <header>
      <input type="text" placeholder="回车搜索商品" @keydown.13="search" />
    </header>
    <!-- 左边导航 -->
    <ul class="left">
      <li v-for="item in cate" :key="item.id" @click="change(item.pid)">
        {{ item.title }}
      </li>
    </ul>

    <!-- 右边信息 -->
    <div class="right">
      <!-- 轮播 -->
      <div class="swiper">
        <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
          <van-swipe-item>
            <img src="@/assets/image/list-swiper01.jpg" alt="" />
          </van-swipe-item>
          <van-swipe-item
            ><img src="@/assets/image/list-swiper02.jpg" alt=""
          /></van-swipe-item>
          <van-swipe-item
            ><img src="@/assets/image/list-swiper03.jpg" alt=""
          /></van-swipe-item>
          <van-swipe-item
            ><img src="@/assets/image/list-swiper04.jpg" alt=""
          /></van-swipe-item>
        </van-swipe>
      </div>

      <!-- 信息 -->
      <ul>
        <li v-for="item in result" :key="item.id">
          <img :src="item.icon" alt="" />
          <p>{{ item.name }}</p>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
import { getshoplist } from "@/utils/api/home.js";
export default {
  data() {
    return {
      cate: [
        { id: 1, title: "所有分类", pid: "0" },
        { id: 2, title: "居家", pid: "15124" },
        { id: 3, title: "配件装饰", pid: "15116" },
        { id: 4, title: "服装", pid: "15115" },
        { id: 5, title: "电器", pid: "15114" },
      ],
      list: [], //原数组-全部数据
      active: "0",
      result: [], // 筛选过的数组
    };
  },
  mounted() {
    getshoplist().then((res) => {
      console.log(res);
      this.list = res.data;
      // this.change(); //进页面展示
      this.result = this.list;
    });
  },
  methods: {
    change(id) {
      this.active = id; //id随便的参数
      this.result = this.list.filter((item) => {
        return item.pid == this.active;
      });
    },

    // 搜索
    search(e) {
      this.result = this.list.filter((item) => {
        return item.name.includes(e.target.value)
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.box {
  font-size: 0.24rem;
  // 头部搜索框
  header {
    z-index: 1;
    position: fixed;
    top: 0;
    background-color: #fff;
    width: 100%;
    padding-left: 0.3rem;
    border-bottom: 0.01rem solid #f3f3f3;
    height: 0.737rem; //36.85
    line-height: 0.737rem;
    input {
      background: #f5f5f5;
      border: 0;
      height: 0.5048rem; //25.24
      width: 5.293rem; //264.65
      //   缩进
      text-indent: 1em;
      border-radius: 0.4rem;
    }
  }

  // 左侧导航
  .left {
    position: fixed;
    top: 0.737rem;
    left: 0;
    background-color: #fff;
    box-sizing: border-box;
    color: #675d56;
    font-size: 0.2884rem; //14.42
    height: 100%;
    border-right: 0.01rem solid #e9e9e9;
    border-top: 0.01rem solid #e9e9e9;
    // width: 1.8748rem;  //93.74
    width: 25%;
    text-align: center;
    > li {
      width: 100%;
      height: 0.721rem; //36.05
      line-height: 0.721rem;
      padding-top: 0.1rem;
    }
  }

  //右侧信息
  .right {
    box-sizing: border-box;
    float: right;
    width: 75%;
    margin-top: 0.737rem;
    margin-bottom: 1.2rem; //61.41px
    //轮播
    .swiper {
      width: 100%;
      height: 2.66rem; //133
      margin: 0.2rem 0;
      .my-swipe {
        height: 100%;
        width: 4.52rem; //226
        margin: auto;
        img {
          height: 100%;
          width: 100%;
          border-radius: 0.1rem;
        }
      }
    }
    // 信息
    ul {
      display: flex;
      flex-wrap: wrap;
      justify-content: space-evenly;
      > li {
        width: 1.5866rem; //79.33
        img {
          width: 100%;
          height: 1.5866rem;
        }
        p {
          text-align: center;
          margin: 0.1rem 0;
        }
      }
    }
  }
}
</style>
